package com.xja.git.service.impl;

import com.xja.git.entity.Entry;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xja.git.entity.Entry;
import com.xja.git.entity.Entry;
import com.xja.git.mapper.BlogUserMapper;
import com.xja.git.mapper.CategoryMapper;
import com.xja.git.mapper.ConmmentMapper;
import com.xja.git.mapper.EntryMapper;
import com.xja.git.service.EntryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 作者：罗帅
 * 当前类所在包：com.xja.git.service.impl
 * 创建时间：2022/8/17下午 5:11 星期三
 * 此类简介：
 */
@Service
public class EntryServiceImpl implements EntryService {
    @Autowired
    private BlogUserMapper blogUserMapper;
    @Autowired
    private CategoryMapper categoryMapper;
    @Autowired
    private ConmmentMapper conmmentMapper;
    @Autowired
    private EntryMapper entryMapper;

    public BlogUserMapper getBlogUserMapper() {
        return blogUserMapper;
    }

    public void setBlogUserMapper(BlogUserMapper blogUserMapper) {
        this.blogUserMapper = blogUserMapper;
    }

    public CategoryMapper getCategoryMapper() {
        return categoryMapper;
    }

    public void setCategoryMapper(CategoryMapper categoryMapper) {
        this.categoryMapper = categoryMapper;
    }

    public ConmmentMapper getConmmentMapper() {
        return conmmentMapper;
    }

    public void setConmmentMapper(ConmmentMapper conmmentMapper) {
        this.conmmentMapper = conmmentMapper;
    }

    public EntryMapper getEntryMapper() {
        return entryMapper;
    }

    public void setEntryMapper(EntryMapper entryMapper) {
        this.entryMapper = entryMapper;
    }

    /**
     * 修改日志
     * @param entry
     */
    @Override
    public void modifyEntry(Entry entry) {
        entryMapper.updateByPrimaryKeySelective(entry);
    }

    /**
     * 添加
     * @param entry
     * @return
     */
    @Override
    public int addEntry(Entry entry) {
        return entryMapper.insertSelective(entry);
    }
    /*
    *
    * 分页查询日志表的方法
    * */
    @Override
    public PageInfo<Entry> queryALL(Integer npage) {
        //分页 指定每页的 条数 以及传进来的页数
        PageHelper.startPage(npage,2);
        //调用方法  service层的方法 并封装到页面中
        List<Entry> entryList = entryMapper.selectByAll();
        return new PageInfo<Entry>(entryList);
    }
    /*
    *
    * 删除的方法
    * */
    @Override
    public int removeByPrimaryKey(Integer id) {
        return entryMapper.deleteByPrimaryKey(id);
    }

    /**
     * 查询日志的方法
     * @param entryId
     * @return
     */
    @Override
    public Entry findEnptyByIdL(Integer entryId) {
        return entryMapper.selectByPrimaryKey(entryId);
    }


    @Override
    public PageInfo<Entry> findAllEnptyL(Integer npage) {
        PageHelper.startPage(npage,2);
        List<Entry> entries = entryMapper.selectByAll();
        return new PageInfo<>(entries);
    }
}
